/*
The MIT License (MIT)

Copyright (c) 2013 Mike Dapiran, Brian May, Richard Pospesel, and Bert Wierenga

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software 
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#pragma once

#include "Hogshead.Common.h"
#include "Hogshead.Core.h"

#include "../Directors/IProcess.h"
#include "../HLSLCPPDeclarations/ConstantBuffers.fx"

struct ID3D11Buffer;

namespace Hogshead
{
	namespace DX11Rendering
	{
		class PointLight;
		class DirectionalLight;
		class MeshRenderer;
		class Material;
		class VertexShader;
		class GeometryShader;
		class PixelShader;
		class DX11Mesh;
		class RasterizerState;
		class BlendState;
		class SamplerState;
		class DepthStencilState;
		class HullShader;
		class DomainShader;


		/**
		* This class is the process that will render all MeshRenderer's that register with it.
		*
		* @see MeshRenderer
		* @see Camera
		* @see IProcess
		* @see IDirector
		*
		* @author Bert Wierenga
		* @author Mike Dapiran
		*/
		class MeshProcess : public IProcess
		{
			ProcessH(Hogshead::DX11Rendering::MeshProcess, MeshProcess)
		public:
			MeshProcess(void);
			~MeshProcess(void);

			void initialize();
			void registerComponent(IComponent* in_component);
			void MeshProcess::unregisterComponent( IComponent* in_component );

			void render(Camera* in_active_camera, HashSet<void*>* in_nonculled_components);

		private:

			//use this to have a contiguous block to copy as register 0
			//this process will always assume control of register 0!
			WVP _world_view_projection;
			//also need to hold onto the buffer object to update
			ID3D11Buffer* _world_view_projection_buffer;


			//-----------------------
			// These objects are used to not bind objects already bound to the 
			// graphics pipeline
			VertexShader* _prev_vertex_shader;
			PixelShader* _prev_pixel_shader;
			GeometryShader* _prev_geometry_shader;
			HullShader* _prev_hull_shader;
			DomainShader* _prev_domain_shader;

			RasterizerState* _prev_rasterizer_state;
			BlendState* _prev_blend_state;
			SamplerState* _prev_sampler_state;
			DepthStencilState* _prev_depth_stencil_state;

			//------------------------
			// These are Components we know what we want to do with
			Vector<MeshRenderer*> _unlit_meshes;
			Vector<MeshRenderer*> _lit_meshes;
			

		};
	}
}
